#!/usr/bin/env python
# coding:utf-8
"""
@Version: V1.0
@Author: willson
@License: Apache Licence
@Contact: willson.wu@goertek.com
@Site: goertek.com
@Software: PyCharm
@File: mainWindow.py
@Time: 18-11-8 下午4:06
"""

import random

from PyQt5.QtCore import QEvent
from PyQt5.QtWidgets import QMainWindow, QMessageBox, QWidget

from ui.Ui_mainWindow import Ui_MainWindow


# 主窗口逻辑处理部分
class MainWindow(QMainWindow, Ui_MainWindow):
    def __init__(self):
        super(MainWindow, self).__init__()
        self.setupUi(self)

        # 获取按钮文字
        self.buttonYesText = self.pushButtonYes.text()
        self.buttonNoText = self.pushButtonNo.text()

        # 设置鼠标跟踪
        self.pushButtonYes.setMouseTracking(True)
        self.pushButtonNo.setMouseTracking(True)
        # 安装事件筛选器
        self.pushButtonYes.installEventFilter(self)
        self.pushButtonNo.installEventFilter(self)

    def timerEvent(self, QTimerEvent):
        # 定时器事件
        # self.pushButtonYes.setText(self.buttonYesText)
        self.update()

    def about_button_click(self):
        QMessageBox.information(self, "关于", "willson.wu@goertek.com")

    def closeEvent(self, event):
        # 主窗口关闭事件
        msg = QMessageBox.warning(self, 'Love', '(;´༎ຶД༎ຶ`) 你要离我而去吗?', QMessageBox.Yes | QMessageBox.No,
                                  QMessageBox.Yes)
        if msg == QMessageBox.Yes:
            event.ignore()
            QMessageBox.about(self, 'Love', '(๑•̀ㅂ•́)و✧想关掉?不存在的！')
        else:
            event.ignore()

    def changeEvent(self, event):
        # 窗口改变事件
        if event.type() == QEvent.WindowStateChange:
            if self.isMinimized():
                # 最小化
                QMessageBox.about(self, 'Love', '(ノへ￣、)不许隐藏我！')
            elif self.isMaximized():
                # 最大化
                QMessageBox.about(self, 'Love', '（づ￣3￣）づ╭❤～对对对,全屏欣赏我！')
            elif self.isFullScreen():
                # 全屏
                QMessageBox.about(self, 'Love', '凸(艹皿艹 )我的大脸(全屏)不好看吗?')
            elif self.isActiveWindow():
                # 活动窗口
                QMessageBox.about(self, 'Love', '凸(艹皿艹 )我的大脸(全屏)不好看吗?')
        QWidget.changeEvent(self, event)

    def eventFilter(self, QObject, QEvent):
        # 事件筛选器
        if QObject == self.pushButtonNo:
            if QEvent.type() == QEvent.Enter:
                # 鼠标焦点在No按钮上
                self.pushButtonNoMove()
        elif QObject == self.pushButtonYes:
            if QEvent.type() == QEvent.Enter:
                # 鼠标焦点在Yes按钮上
                self.pushButtonYesMove()
            elif QEvent.type() == QEvent.MouseButtonRelease:
                # No按下按钮
                self.pushButtonYesPress()
            elif QEvent.type() == QEvent.MouseButtonPress:
                self.pushButtonYes.setText("我真牛")

        return QMainWindow.eventFilter(self, QObject, QEvent)

    def pushButtonYesMove(self):
        # 光标在Yes按钮上响应事件
        self.pushButtonYes.setText(self.buttonYesText)

    def pushButtonYesPress(self):
        # 光标在Yes 按钮按下响应事件
        QMessageBox.about(self, 'Love', '（づ￣3￣）づ╭❤～我也是这样认为的!')

    def pushButtonNoMove(self):
        # 光标在NO按钮上响应事件
        ret = self.geometry()
        width = ret.width()
        height = ret.height()
        self.pushButtonNo.move(random.randint(10, width - 30), random.randint(10, height - 30))


if __name__ == '__main__':
    pass
